<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,java.io.*"%>
<%@page import="com.oa.base.web.office.SmartUpload"%>
<%@page import="com.oa.base.web.office.File"%>

<%
java.io.InputStream inStream = null;
java.io.OutputStream outStream = null;
	try{
		//获取文件
		SmartUpload mysmartUp=new SmartUpload();
		mysmartUp.initialize(pageContext);
		mysmartUp.upload();
		String orgPath = mysmartUp.getRequest().getParameter("orgPath");
		
		//定义上传的文件
		com.oa.base.web.office.File myFile = mysmartUp.getFiles().getFile(0);
		String filePath=myFile.getFileName();
		
		if(!myFile.isMissing()){
		    
			myFile.saveAs(filePath,mysmartUp.SAVE_PHYSICAL);	
			java.io.File tfile = new java.io.File(filePath);
			
			inStream=new java.io.FileInputStream(tfile);
			outStream = new FileOutputStream(orgPath);
			
			byte[] buffer = new byte[1024];
            int length = 0; 
            while ( (length = inStream.read(buffer)) != -1) {
            	outStream.write(buffer, 0, length);
            } 
			
            outStream.flush();
			out.clear();
			out.write("succeed");
			out.flush();
			
			
			if(tfile.exists()) {
				tfile.delete();
			}
		}		
		
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		if(inStream != null){inStream.close();}
		if(outStream != null){outStream.close();}
	}
%>